package role

import (
	"context"

	"go-zero-mall/app/admin/cmd/api/internal/svc"
	"go-zero-mall/app/admin/cmd/api/internal/types"
	"go-zero-mall/app/admin/cmd/rpc/pd"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type RoleListMenuLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoleListMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleListMenuLogic {
	return &RoleListMenuLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleListMenuLogic) RoleListMenu(req *types.RoleListMenuReq) (resp *types.RoleListMenuResp, err error) {
	var in pd.UmsRoleListMenuReq
	copier.Copy(&in, req)
	d, err := l.svcCtx.AdminRpc.RoleListMenu(l.ctx, &in)
	if err != nil {
		return nil, err
	}
	resp = &types.RoleListMenuResp{
		MenuIds: d.MenuIds,
		RoleId:  d.RoleId,
	}
	return resp, err
}
